package com.yk.system.service.impl;

import java.util.List;
import com.yk.common.utils.DateUtils;
import com.yk.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yk.system.mapper.SysIndexPictureMapper;
import com.yk.system.domain.SysIndexPicture;
import com.yk.system.service.ISysIndexPictureService;
import com.yk.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 首页图片Service业务层处理
 *
 * @author xufei
 * @date 2025-04-28
 */
@Service
public class SysIndexPictureServiceImpl implements ISysIndexPictureService
{
    @Autowired
    private SysIndexPictureMapper sysIndexPictureMapper;

    /**
     * 查询首页图片
     *
     * @param id 首页图片主键
     * @return 首页图片
     */
    @Override
    public SysIndexPicture selectSysIndexPictureById(Long id)
    {
        return sysIndexPictureMapper.selectSysIndexPictureById(id);
    }

    /**
     * 查询首页图片列表
     *
     * @param sysIndexPicture 首页图片
     * @return 首页图片
     */
    @Override
    public List<SysIndexPicture> selectSysIndexPictureList(SysIndexPicture sysIndexPicture)
    {
        return sysIndexPictureMapper.selectSysIndexPictureList(sysIndexPicture);
    }

    /**
     * 新增首页图片
     *
     * @param sysIndexPicture 首页图片
     * @return 结果
     */
    @Override
    public int insertSysIndexPicture(SysIndexPicture sysIndexPicture)
    {
        sysIndexPicture.setCreateBy(ShiroUtils.getLoginName());
        sysIndexPicture.setCreateTime(DateUtils.getNowDate());
        sysIndexPicture.setStatus("0");
        sysIndexPicture.setDelFlag("0");
        return sysIndexPictureMapper.insertSysIndexPicture(sysIndexPicture);
    }

    /**
     * 修改首页图片
     *
     * @param sysIndexPicture 首页图片
     * @return 结果
     */
    @Override
    public int updateSysIndexPicture(SysIndexPicture sysIndexPicture)
    {
        sysIndexPicture.setUpdateTime(DateUtils.getNowDate());
        sysIndexPicture.setUpdateBy(ShiroUtils.getLoginName());
        return sysIndexPictureMapper.updateSysIndexPicture(sysIndexPicture);
    }


    @Override
    @Transactional
    public int changeStatus(SysIndexPicture sysIndexPicture) {
        // 先将启用状态的图片停用
        sysIndexPictureMapper.upDateStatusOff();
        sysIndexPicture.setUpdateTime(DateUtils.getNowDate());
        sysIndexPicture.setUpdateBy(ShiroUtils.getLoginName());
        return sysIndexPictureMapper.updateSysIndexPicture(sysIndexPicture);
    }

    /**
     * 批量删除首页图片
     *
     * @param ids 需要删除的首页图片主键
     * @return 结果
     */
    @Override
    public int deleteSysIndexPictureByIds(String ids)
    {
        return sysIndexPictureMapper.deleteSysIndexPictureByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除首页图片信息
     *
     * @param id 首页图片主键
     * @return 结果
     */
    @Override
    public int deleteSysIndexPictureById(Long id)
    {
        return sysIndexPictureMapper.deleteSysIndexPictureById(id);
    }

}
